use std::sync::mpsc;
use std::thread;
use std::time::Duration;

fn main() {
    // let handle = thread::spawn(|| {
    //     for i in 1..10 {
    //         println!("thei number {} from the spawned thread,,,", i);
    //         thread::sleep(Duration::from_millis(1));
    //     }
    // });

    // for i in 1..5 {
    //     println!("thei number {} from the main thread!!!", i);
    //     thread::sleep(Duration::from_millis(1));
    // }
    println!("Hello, world!");

    // handle.join().unwrap();

    // let v = vec![1, 2, 3];
    // let handle = thread::spawn(move || {
    //     println!("here is the vector: {:?}", v);
    // });
    // handle.join();

    let (tx, rx) = mpsc::channel();
    thread::spawn(move || {
        // let val = String::from("hi value");
        // tx.send(val).unwrap();
        let vals = vec![
            String::from("hi"),
            String::from("from"),
            String::from("the"),
            String::from("thread"),
        ];
        for val in vals {
            tx.send(val).unwrap();
            thread::sleep(Duration::from_millis(1));
        }
    });
    // let received = rx.recv().unwrap();
    // println!("Got: {}", received);
    for received in rx {
        println!("got:{}", received);
    }
}
